package com.dayou.controller;

import java.util.List;

import com.dayou.bean.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import com.dayou.service.ISysUserService;
import com.dayou.common.core.controller.BaseController;
import com.dayou.common.core.page.TableDataInfo;
import com.dayou.common.core.domain.AjaxResult;
import com.dayou.common.utils.poi.ExcelUtil;

import javax.servlet.http.HttpServletRequest;

/**
 * 达幽系统集成框架 - 用户 信息操作处理
 * 
 * @author dayou
 * @date 2020-04-23
 */
@Controller
@RequestMapping("/sysUser")
public class SysUserController extends BaseController
{
    private String prefix = "sysUser";

	@Autowired
	private ISysUserService sysUserService;

	@GetMapping()
	public String sysUser()
	{
		return prefix + "/sysUser";
	}


	/**
	 * 查询达幽系统集成框架 - 用户列表
	 */
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(@RequestBody SysUser sysUser)
	{
		startPage();
		List<SysUser> list = sysUserService.selectSysUserList(sysUser);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出达幽系统集成框架 - 用户列表
	 */
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(@RequestBody SysUser sysUser)
    {
    	List<SysUser> list = sysUserService.selectSysUserList(sysUser);
        ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class);
        return util.exportExcel(list, "sysUser");
    }
	
	/**
	 * 新增保存达幽系统集成框架 - 用户
	 */
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(@RequestBody SysUser sysUser)
	{		
		return toAjax(sysUserService.insertSysUser(sysUser));
	}

	/**
	 * 修改保存达幽系统集成框架 - 用户
	 */
	@PutMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(@RequestBody SysUser sysUser)
	{
		return toAjax(sysUserService.updateSysUser(sysUser));
	}

	/**
	 * 伪删除达幽系统集成框架 - 用户
	 */
	@DeleteMapping( "/fakeDelete")
	@ResponseBody
	public AjaxResult fakeDelete(@RequestParam String ids)
	{
		System.out.println(ids);
		return null;
	}

	/**
	 * 删除达幽系统集成框架 - 用户
	 */
	@DeleteMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(@RequestParam String ids)
	{
		return toAjax(sysUserService.deleteSysUserByIds(ids));
	}
	
}
